/*
 * @Author: ziqi jhzq12345678
 * @Date: 2024-10-15 17:33:23
 * @LastEditors: ziqi jhzq12345678
 * @LastEditTime: 2025-01-24 20:37:34
 * @FilePath: /pornhub_app/lib/src/components/ad_banner/insert_ad.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:pornhub_app/assets/styles.dart';
import 'package:pornhub_app/utils/color.dart';

import '../../utils/ad_jump.dart';
import '../../utils/ad_utils.dart';
import '../../utils/extension.dart';
import '../../utils/initAdvertisementInfo.dart';
import '../image_view.dart';

class InsertAd extends StatelessWidget {
  final String adress;
  final double? height;
  final double? width;
  final bool? mark;
  final bool? hasTitle;
  final EdgeInsets? margin;
  InsertAd(
      {super.key,
      required this.adress,
      double? width,
      double? height,
      this.hasTitle = false,
      this.mark = true,
      this.margin})
      : height = height ?? 120.w,
        width = width ?? 372.w;

  InsertAd.fromPlaceholder(
    InsertAdPlaceHolderModel placeholder, {
    super.key,
    this.width = double.infinity,
    required this.height,
    this.mark = true,
    this.hasTitle = false,
    this.margin,
  }) : adress = placeholder.place;

  @override
  Widget build(BuildContext context) {
    final ad = initWeightAdvertisementInfo(adress);
    if (ad == null) return const SizedBox.shrink();
    return Container(
        width: width,
        margin: margin,
        child: Column(
          children: [
            Stack(
              children: [
                Container(
                  width: width,
                  height: height,
                  clipBehavior: Clip.hardEdge,
                  decoration:
                      BoxDecoration(borderRadius: Styles.borderRadius.m),
                  child: ImageView(
                    src: ad.adImage ?? '',
                    fit: BoxFit.fill,
                  ),
                ),
                mark == true
                    ? Positioned(
                        right: 3.w,
                        bottom: 3.w,
                        child: Container(
                          padding: EdgeInsets.symmetric(
                              horizontal: 5.w, vertical: 1.w),
                          decoration: BoxDecoration(
                              color: const Color.fromRGBO(0, 0, 0, 0.7),
                              borderRadius: BorderRadius.circular(2.w)),
                          child: Text(
                            '广告',
                            style:
                                TextStyle(color: Colors.white, fontSize: 10.w),
                          ),
                        ))
                    : const SizedBox.shrink()
              ],
            ),
            Padding(padding: EdgeInsets.only(top: hasTitle == true ? 8.w : 0)),
            hasTitle == true
                ? SizedBox(
                    width: width!.w,
                    child: Text(
                      maxLines: 2,
                      '${ad.adName}',
                      style: TextStyle(
                          color: COLOR.hexColor('#ffffff'), fontSize: 14.w),
                    ),
                  )
                : const SizedBox.shrink(),
          ],
        )).onOpaqueTap(() {
      kAdjump(ad, ad.adId);
    });
  }
}
